package com.me.utils;

import java.util.ArrayList;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
import com.me.constant.Constant;
import com.me.helper.PreferencesData;
import com.me.info.MyImage;
import com.me.memorytest.MainMemoryTest;

public class ProcessData {

	// Tạo số ngẫu nhiên
	public static void RandomNumber(ArrayList<Integer> listRand, int n) {
		ArrayList<Integer> listRand1 = new ArrayList<Integer>();
		ArrayList<Integer> listRand2 = new ArrayList<Integer>();
		listRand.clear();
		// random n unique number
		int iNew = 0;
		for (int i = 0; i < n;) {
			iNew = MathUtils.random.nextInt(n + 1);
			if (!listRand1.contains(iNew) && iNew != 0) {
				i++;
				listRand1.add(iNew);
			}
		}
		for (int i = 0; i < n;) {
			iNew = MathUtils.random.nextInt(n + 1);
			if (!listRand2.contains(iNew) && iNew != 0) {
				i++;
				listRand2.add(iNew);
			}
		}
		listRand.addAll(listRand1);
		listRand.addAll(listRand2);
	}

	// Get image
	public static ArrayList<MyImage> getImage(ArrayList<Integer> listRandEdited) {
		ArrayList<MyImage> listImage = new ArrayList<MyImage>();
		MyImage img = null;

		// Lấy hình theo danh mục
		// 1 - Animal; 2 - Fruit; 3 - Sea; 4 - Flag; 5 - People
		int icategory = PreferencesData.getCategory();
		String strCategory = "animalPic/animal";
		switch (icategory) {
		case 1:
			strCategory = "animalPic/animal";
			break;
		case 2:
			strCategory = "fruitPic/fruit";
			break;
		case 3:
			strCategory = "seaPic/fish";
			break;
		case 4:
			strCategory = "flagPic/flag";
			break;
		default:
			break;
		}

		for (int i = 0; i < listRandEdited.size(); i++) {
			TextureRegionDrawable imgDefault = new TextureRegionDrawable(
					MainMemoryTest.getAtlas().findRegion("datagame/defaulImg"));
			TextureRegionDrawable imgValue = new TextureRegionDrawable(
					MainMemoryTest.getAtlas().findRegion(strCategory,
							listRandEdited.get(i)));
			img = new MyImage(imgDefault, imgValue, listRandEdited.get(i), i);
			img.getImg().setWidth(Constant.wh_Image);
			img.getImg().setHeight(Constant.wh_Image);
			listImage.add(img);
		}
		return listImage;
	}

	public static String getName(int id) {
		String name = "";
		int iCategory = PreferencesData.getCategory();

		switch (iCategory) {
		case 1: {
			switch (id) {
			case 1:
				name = "CAT";
				return name;
			case 2:
				name = "BULL";
				return name;
			case 3:
				name = "GOAT";
				return name;
			case 4:
				name = "LION";
				return name;
			case 5:
				name = "CHICKEN";
				return name;
			case 6:
				name = "MONKEY";
				return name;
			case 7:
				name = "TURTLE";
				return name;
			case 8:
				name = "ZEBRA";
				return name;
			case 9:
				name = "DUCK";
				return name;
			case 10:
				name = "PIG";
				return name;
			case 11:
				name = "DONKEY";
				return name;
			case 12:
				name = "DOG";
				return name;
			case 13:
				name = "PENGUIN";
				return name;
			case 14:
				name = "SNAKE";
				return name;
			case 15:
				name = "SQUID";
				return name;
			case 16:
				name = "ELEPHANT";
				return name;
			case 17:
				name = "HEN";
				return name;
			case 18:
				name = "PANDA";
				return name;
			case 19:
				name = "BEAR";
				return name;
			}
			break;
		}
		case 2: {
			switch (id) {
			case 1:
				name = "Apricot";
				return name;
			case 2:
				name = "Grapefruit";
				return name;
			case 3:
				name = "Banana";
				return name;
			case 4:
				name = "Coconut";
				return name;
			case 5:
				name = "Grape";
				return name;
			case 6:
				name = "Kiwi";
				return name;
			case 7:
				name = "Lemon";
				return name;
			case 8:
				name = "Mango";
				return name;
			case 9:
				name = "Maracuja";
				return name;
			case 10:
				name = "Orange";
				return name;
			case 11:
				name = "Peach";
				return name;
			case 12:
				name = "Pear";
				return name;
			case 13:
				name = "Pineapple";
				return name;
			case 14:
				name = "Red watermelon";
				return name;
			case 15:
				name = "Starfruit";
				return name;
			case 16:
				name = "Strawberry";
				return name;
			case 17:
				name = "Tomato";
				return name;
			case 18:
				name = "Yellow watermelon";
				return name;
			case 19:
				name = "Apple";
				return name;
			}
			break;
		}
		case 3: {
			switch (id) {
			case 1:
				name = "Crab";
				return name;
			case 2:
				name = "Dolphin";
				return name;
			case 3:
				name = "Shark";
				return name;
			case 4:
				name = "Seahorse";
				return name;
			case 5:
				name = "Seahorse";
				return name;
			case 6:
				name = "Dolphin";
				return name;
			case 7:
				name = "Star";
				return name;
			case 8:
				name = "Starfish";
				return name;
			case 9:
				name = "Gold fish";
				return name;
			case 10:
				name = "Gold fish";
				return name;
			case 11:
				name = "Seahorse";
				return name;
			case 12:
				name = "Octopus";
				return name;
			case 13:
				name = "Fish";
				return name;
			case 14:
				name = "Fish";
				return name;
			case 15:
				name = "Fish";
				return name;
			case 16:
				name = "Fish";
				return name;
			case 17:
				name = "Fish";
				return name;
			case 18:
				name = "Fish";
				return name;
			case 19:
				name = "Fish";
				return name;
			}
			break;
		}
		case 4: {
			switch (id) {
			case 1:
				name = "VietNam";
				return name;
			case 2:
				name = " United Stage";
				return name;
			case 3:
				name = "Ukraine";
				return name;
			case 4:
				name = "Turkey";
				return name;
			case 5:
				name = "Thailand";
				return name;
			case 6:
				name = "Spain";
				return name;
			case 7:
				name = "Somilia";
				return name;
			case 8:
				name = "Singapore";
				return name;
			case 9:
				name = "Japan";
				return name;
			case 10:
				name = "Italy";
				return name;
			case 11:
				name = "Iran";
				return name;
			case 12:
				name = "Hungary";
				return name;
			case 13:
				name = "Germany";
				return name;
			case 14:
				name = "France";
				return name;
			case 15:
				name = "English";
				return name;
			case 16:
				name = "China";
				return name;
			case 17:
				name = "Chile";
				return name;
			case 18:
				name = "Brazil";
				return name;
			case 19:
				name = "Australia";
				return name;
			}
			break;
		}
		case 5: {
			switch (id) {
			case 1:
				return name;
			case 2:
				return name;
			case 3:
				return name;
			case 4:
				return name;
			case 5:
				return name;
			case 6:
				return name;
			case 7:
				return name;
			case 8:
				return name;
			case 9:
				return name;
			case 10:
				return name;
			case 11:
				return name;
			case 12:
				return name;
			case 13:
				return name;
			case 14:
				return name;
			case 15:
				return name;
			case 16:
				return name;
			case 17:
				return name;
			case 18:
				return name;
			case 19:
				return name;
			}
			break;
		}
		}
		return name;
	}

	// sortAsc sắp xếp Tăng dần
	// public static ArrayList<Integer> sortAsc(ArrayList<Integer> _listScore,
	// ArrayList<String> _listUserName) {
	// for (int i = 0; i < _listScore.size(); i++) {
	// for (int j = _listScore.size() - 1; j > i; j--) {
	// if (_listScore.get(j) < _listScore.get(j - 1)) {
	// int t = _listScore.get(j);
	// _listScore.set(j, _listScore.get(j - 1));
	// _listScore.set(j - 1, t);
	//
	// String str = _listUserName.get(j);
	// _listUserName.set(j, _listUserName.get(j - 1));
	// _listUserName.set(j - 1, str);
	// }
	// }
	// }
	//
	// return _listScore;
	// }

	// public static void ReSave_Score() {
	// ArrayList<Integer> listScore = new ArrayList<Integer>();
	// ArrayList<String> listUserName = new ArrayList<String>();
	//
	// // Lấy tên và điểm trong Prefs
	// for (int i = 1; i < 6; i++) {
	// listScore.add(PreferencesData.getHighScore(i));
	// listUserName.add(PreferencesData.getUserName(i));
	// }
	//
	// // Sắp xếp lại tên và điểm theo thứ tự điểm tăng dần
	// ProcessData.sortAsc(listScore, listUserName);
	//
	// // Add lại tên và điểm sau khi sắp xếp
	// for (int i = 1; i < 6; i++) {
	// PreferencesData.setUserName(listUserName.get(i - 1), i);
	// PreferencesData.setHighScore(listScore.get(i - 1), i);
	// }
	// }

	/*
	 * public static TextureRegion[] sliptTexture(TextureRegion img, int cols,
	 * int rows) { TextureRegion[][] a = img.split(img.getRegionWidth()/cols,
	 * img.getRegionHeight()/rows); TextureRegion[] kq = new
	 * TextureRegion[cols*rows]; int k = 0; for(int i=0; i<rows; i++) for(int
	 * j=0; j<cols; j++) kq[k++] = a[i][j]; return kq; }
	 */
}
